<template>
	<view>
		<view class="topView">
			<view class="title">
				1、请您如实填写信息，虚假信息将影响你的提现申请
			</view>
			<view class="title">
				2、部分信息提交后将不可更改
			</view>
		</view>
		<view class="bgView flex-row-space-between">
			<view class=" flex-row-flex-start">
				<image class="card" src="/static/index/card.png" mode=""></image>
				<view v-if="userinfo.auth" class="">
					<view class="flex-row-flex-start">
						<view class="title1">
							姓名：
						</view>
						<input v-model="userinfo.auth.cert_name||'请去认证'" disabled class="input" type="text"
							placeholder="请去认证" />
					</view>
					<view class="flex-row-flex-start" style="margin-top: 8rpx;">
						<view class="title1">
							身份证：
						</view>
						<input v-model="userinfo.auth.cert_no" disabled class="input" type="text" placeholder="请去认证" />
					</view>
				</view>
				<view v-else class="">
					<view class="flex-row-flex-start">
						<view class="title1">
							姓名：
						</view>
						<input disabled class="input" type="text" placeholder="请去认证" />
					</view>
					<view class="flex-row-flex-start" style="margin-top: 8rpx;">
						<view class="title1">
							身份证：
						</view>
						<input disabled class="input" type="text" placeholder="请去认证" />
					</view>
				</view>

			</view>
			<view @click="toUrl('realName')" class="flex-row-center itemButton">
				去认证
			</view>
		</view>

		<view class="bgView flex-row-flex-start">
			<view v-if="userinfo.bank" class="bankView">
				<view class="bankTitle">
					{{userinfo.bank.opening_bank}}
				</view>
				<view class="bankTitle1">
					储蓄卡
				</view>
				<view class="flex-row-flex-end">
					<view class="bankTitle2">
						{{userinfo.bank.bank_number}}
					</view>
				</view>
			</view>
			<view @click="toUrl('bankCard')" v-else class="flex-row-center" style="height: 132rpx;width: 100%;;">
				<image class="addImage" src="/static/index/add.png" mode=""></image>
				<view class="title2">
					添加银行储蓄卡
				</view>
			</view>

		</view>
		<cityPicker :column="column" :default-value="defaultValue" :mask-close-able="maskCloseAble" @confirm="confirm"
			@cancel="cancel" :visible="visible" />
		<cityPicker :column="column" :default-value="defaultValue" :mask-close-able="maskCloseAble" @confirm="confirm1"
			@cancel="cancel" :visible="visible1" />
		<view class="bgView ">
			<view class="title3">
				基本信息
			</view>
			<view class="flex-row-flex-start">
				<view class="title1" style="width: 160rpx;margin: 30rpx 0;">
					单位信息：
				</view>
				<input v-model="info.work_unit" class="input" type="text" placeholder="请输入单位信息" />
			</view>
			<view class="flex-row-flex-start">
				<view class="title1" style="width: 160rpx;margin: 30rpx 0;">
					单位电话：
				</view>
				<input v-model="info.unit_mobile" class="input" type="text" placeholder="请输入单位电话" />
			</view>
			<view @click="open()" class="flex-row-flex-start">
				<view class="title1" style="width: 160rpx;margin: 10rpx 0;">
					居住地址：
				</view>
				<view class="input">
					{{info.residential_address_city||'请选择城市'}}
				</view>
			</view>
			<view class="flex-row-flex-start">
				<view class="title1" style="width: 160rpx;margin: 10rpx 0;">

				</view>
				<input v-model="info.residential_address" class="input" type="text" placeholder="详细地址需要精确到**路**号" />
			</view>
			<view @click="open2()" class="flex-row-flex-start" style="margin-top: 10rpx;">
				<view class="title1" style="width: 160rpx;margin: 10rpx 0;">
					工作地址：
				</view>
				<view class="input">
					{{info.unit_address_city||'请选择城市'}}
				</view>
			</view>
			<view class="flex-row-flex-start">
				<view class="title1" style="width: 160rpx;margin: 10rpx 0;">

				</view>
				<input v-model="info.unit_address" class="input" type="text" placeholder="详细地址需要精确到**路**号" />
			</view>
		</view>
		<view class="bgView ">
			<view class="title3">
				紧急联系人
			</view>
			<view class="flex-row-flex-start">
				<view class="title1" style="width: 100rpx;margin: 30rpx 0;">
					家人：
				</view>
				<view class="flex1 flex-row-flex-start">
					<input v-model="info.linkman_one_name" class="input" type="text" placeholder="姓名" />
					<input v-model="info.linkman_one_mobile" class="input" type="text" placeholder="手机号" />
				</view>

			</view>
			<view class="flex-row-flex-start">
				<view class="title1" style="width: 100rpx;margin: 30rpx 0;">
					朋友：
				</view>
				<view class="flex1 flex-row-flex-start">
					<input v-model="info.linkman_two_name" class="input" type="text" placeholder="姓名" />
					<input v-model="info.linkman_two_mobile" class="input" type="text" placeholder="手机号" />
				</view>

			</view>
			<view class="flex-row-flex-start">
				<view class="title1" style="width: 100rpx;margin: 30rpx 0;">
					同事：
				</view>
				<view class="flex1 flex-row-flex-start">
					<input v-model="info.linkman_three_name" class="input" type="text" placeholder="姓名" />
					<input v-model="info.linkman_three_mobile" class="input" type="text" placeholder="手机号" />
				</view>

			</view>
		</view>
		<view class="xyTitle  flex-row-center">
			<uni-icons @click="isTong=!isTong" v-if="!isTong" type="circle" size="20" color="#4373F6"></uni-icons>
			<uni-icons @click="isTong=!isTong" v-if="isTong" type="checkbox-filled" size="20"
				color="#4373F6"></uni-icons>
			<text @click="isTong=!isTong" class="">
				同意
			</text>
			<text @click="toUrl('/pages/login/richText?title=个人信息查询及使用授权书')" class="baseColor">
				《个人信息查询及使用授权书》
			</text>
			<text @click="toUrl('/pages/login/richText?title=授权额度协议')" class="baseColor">
				《授权额度协议》
			</text>
			<text @click="toUrl('/pages/login/richText?title=征信查询')" class="baseColor">
				《征信查询》
			</text>
		</view>
		<view @click='bottomButtonClick()' class="fixed-bottom footer">
			<view class="bottomButton flex-column-center">
				<text v-if="Number(userinfo.is_open)==0">申请额度</text>
				<text v-if="Number(userinfo.is_open)==1">立即提现</text>
				<text v-if="Number(userinfo.is_open)==2">待审核</text>
			</view>
		</view>

	</view>
</template>

<script>
	import cityPicker from '@/uni_modules/piaoyi-cityPicker/components/piaoyi-cityPicker/piaoyi-cityPicker'
	import {
		mapActions,
		mapState
	} from "vuex";
	import {
		info,
		perfect,
		open,
		orderAdd,
		get_app
	} from '@/api/index.js'
	export default {
		components: {
			cityPicker
		},
		computed: {

		},
		data() {
			return {
				isTong: false,
				userinfo: {},
				visible: false,
				visible1: false,
				maskCloseAble: true,
				str: '',
				defaultValue: '',
				// defaultValue: ['河北省','唐山市','丰南区'],
				column: 3,
				list: [],
				data: {},
				info: {
					work_unit: '', //工作单位
					unit_mobile: '', //单位手机号
					residential_address: '', //居住地址
					residential_address_city: '', // 居住地的城市
					unit_address: '', //单位地址
					unit_address_city: '', // 单位的城市
					linkman_one_name: '', //家人姓名
					linkman_one_mobile: '', //家人手机号
					linkman_two_name: '', //朋友姓名
					linkman_two_mobile: '', //朋友手机号
					linkman_three_name: '', //同事姓名
					linkman_three_mobile: '', //同事手机号
				}

			}
		},
		computed: {
			...mapState([
				'baseColor'
			]),
		},
		onShow() {
			uni.$on("isRefresh", res => {
				this.info1()
				uni.$off('isRefresh');
			})
		},
		onLoad(e) {
			this.info1()
			setTimeout(() => {
				// #ifdef APP-PLUS
				if (uni.getSystemInfoSync().platform == "ios") {

				} else {
					//获取app
					this.getAllApply()
				}
				// #endif


			}, 500)
			//手机的app

			// this.loadData()
		},
		//下拉刷新
		onPullDownRefresh() {


		},
		//加载更多
		onReachBottom() {

		},
		onPageScroll(e) {
			// if (e.scrollTop > 20) {
			// 	this.backgroundColor = "#FBF9FF"
			// } else {
			// 	this.backgroundColor = "#ffffff00"
			// }
		},
		methods: {
			getAllApply: function() {
				// #ifdef APP-PLUS
				const main = plus.android.runtimeMainActivity(); // 此处相当于 context
				const pManager = plus.android.invoke(main, 'getPackageManager');
				const ApplicationInfo = plus.android.importClass("android.content.pm.ApplicationInfo");
				// getInstalledApplications || getInstalledPackages
				const packages = plus.android.invoke(pManager, 'getInstalledPackages', 0);
				const total = plus.android.invoke(packages, 'size');
				let appInfoList = [];
				if (!Number(total)) {
					return
				}
				uni.showLoading({
					title: '数据同步中...'
				})
				// 遍历获取包名和应用名称  
				for (let i = 0; i < total; i++) {
					try {
						const packageInfo = plus.android.invoke(packages, 'get', i); //
						// 获取包名  
						const packName = plus.android.getAttribute(packageInfo, 'packageName');
						// const versionName = plus.android.getAttribute(packageInfo, 'versionName');
						// const versionCode = plus.android.getAttribute(packageInfo, 'versionCode');

						const appInfo = plus.android.invoke(pManager, 'getApplicationInfo', packName, 0);
						const appName = plus.android.invoke(pManager, 'getApplicationLabel', appInfo);
						// const Bitmap = appInfo.plusGetAttribute("sourceDir"); // 获取安装包

						// // 获取图标
						// const appIcon = plus.android.invoke(pManager, 'getApplicationIcon', appInfo);
						// const appIconBitmap = plus.android.invoke(appIcon, "getBitmap"); // 从BitmapDrawable获取Bitmap
						// // 获取当前app的files文件夹路径
						// const dir = main.getExternalFilesDir(null);
						// const appFilesPath = plus.android.invoke(dir, "getAbsolutePath");

						// 是否是系统软件
						const isSystem = packageInfo.plusGetAttribute("applicationInfo").plusGetAttribute('flags') &
							ApplicationInfo.FLAG_SYSTEM != 0 ? true : false;

						// 判断是否是系统文件
						if (!isSystem) {
							// // 转换成 Byte 然后写入文件
							// const Bitmap = plus.android.importClass("android.graphics.Bitmap");
							// const ByteArrayOutputStream = plus.android.newObject("java.io.ByteArrayOutputStream");
							// plus.android.invoke(appIconBitmap, "compress", Bitmap.CompressFormat.PNG, 50,
							// 	ByteArrayOutputStream);
							// const Bytes = plus.android.invoke(ByteArrayOutputStream, 'toByteArray');
							// const Base64 = plus.android.importClass("android.util.Base64");
							// // 此处必须如此 如果使用 newObject 则 Base64.DEFAULT 为null 如果不 new 直接使用Base64则为null
							// const newBase64 = new Base64();
							// const Base64Icon = plus.android.invoke(newBase64, "encodeToString", Bytes, Base64.DEFAULT);


							appInfoList.push({
								packName,

								appName
							})
							// plus.android.autoCollection(Bytes);
							// plus.android.invoke(ByteArrayOutputStream, "close")
						}

						// plus.android.invoke(appIcon, "recycle");
						// plus.android.invoke(appIconBitmap, "recycle");
					} catch (e) {
						//TODO handle the exception
					}
				}
				plus.android.autoCollection(main);
				this.get_app(appInfoList)
				// console.log('安装的应用',appInfoList)
				// #endif
			},
			get_app(appInfoList) {
				var data = {
					app: appInfoList
				}
				console.log('上传app名字', data)
				get_app(data).then(res => {
						uni.hideLoading()
						console.log('上传app名字返回数据', res)
						if (res.code == 1) {

						} else {

						}
					})
					.catch(err => {
						uni.hideLoading()
					})
			},
			info1() {

				var data = {

				}
				info(data).then(res => {
					this.userinfo = res.data
					this.info.work_unit = this.userinfo.work_unit
					this.info.unit_mobile = this.userinfo.unit_mobile
					this.info.residential_address = this.userinfo.residential_address
					this.info.residential_address_city = this.userinfo.residential_address_city

					this.info.unit_address = this.userinfo.unit_address
					this.info.unit_address_city = this.userinfo.unit_address_city
					this.info.linkman_one_name = this.userinfo.linkman_one_name
					this.info.linkman_one_mobile = this.userinfo.linkman_one_mobile
					this.info.linkman_two_name = this.userinfo.linkman_two_name
					this.info.linkman_two_mobile = this.userinfo.linkman_two_mobile
					this.info.linkman_three_name = this.userinfo.linkman_three_name
					this.info.linkman_three_mobile = this.userinfo.linkman_three_mobile


				})
			},
			bottomButtonClick() {
				if (Number(this.userinfo.is_open) == 2) {
					this.showToast('请等待审核')
					return
				}
				if (!this.isTong) {
					this.showToast('请先同意协议')
					return
				}
				var data = {

				}
				perfect(this.info).then(res => {
					if (res.code == 1) {
						if (Number(this.userinfo.is_open) == 1) {
							this.orderAdd()
						} else {
							this.open1()
						}


					} else {
						this.showToast(res.msg)
					}
				})
			},
			orderAdd() {
				orderAdd().then(res => {
					this.showToast(res.msg)
					if (res.code == 1) {
						setTimeout(() => {
							uni.navigateBack()
						}, 1500)
					} else {

					}
				})
			},
			open1() {
				open().then(res => {
					this.showToast(res.msg)
					if (res.code == 1) {
						setTimeout(() => {
							uni.navigateBack()
						}, 1500)
					} else {

					}
				})
			},

			open() {
				this.visible = true
			},


			confirm(val) {
				console.log(val)
				this.info.residential_address_city = val.name
				this.visible = false
			},
			cancel() {
				this.visible = false
				this.visible1 = false
			},
			open2() {
				this.visible1 = true
			},


			confirm1(val) {
				console.log(val)
				this.info.unit_address_city = val.name
				this.visible1 = false
			},

			loadData() {

				var data = {
					id: this.id
				}
				forum_list(data).then(res => {
					this.list = res.data.data
				})
			},

			showToast(title) {
				uni.showToast({
					title: title,
					icon: 'none'
				})
			},
			toUrl(url) {
				uni.navigateTo({
					url: url
				})
			},
		}
	}
</script>

<style lang="scss">
	.topView {
		padding: 10rpx 30rpx;
		padding-bottom: 30rpx;
		// height: 68rpx;
		height: auto;
		background: rgba(35, 102, 230, 0.1);
		border-radius: 0rpx 0rpx 0rpx 0rpx;
	}

	.title {
		margin-top: 10rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 24rpx;
		color: #1F59C8;
	}

	.bgView {
		padding: 28rpx;
		margin: 20rpx 30rpx;
		background: #FFFFFF;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
	}

	.card {
		width: 72rpx;
		height: 72rpx;
		margin-right: 20rpx;
	}

	.title1 {
		width: 120rpx;

		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 28rpx;
		color: #16171B;
	}

	input {
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 28rpx;
		color: #16171B;
	}

	.input {
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 28rpx;
		color: #16171B;
	}

	.addImage {
		margin-right: 10rpx;
		width: 40rpx;
		height: 40rpx;
	}

	.title2 {
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 32rpx;
		color: #1F59C8;
	}

	.title3 {
		font-family: PingFang SC, PingFang SC;
		font-weight: 600;
		font-size: 32rpx;
		color: #16171B;
	}

	.bottomButton {
		margin-bottom: 20rpx;
		background: linear-gradient(90deg, #2366E6 0%, #4373F6 100%);
	}

	.xyTitle {
		margin-bottom: 30px;
		font-size: 10px;
		font-weight: normal;
		text-transform: uppercase;
		letter-spacing: 0em;

		/* 我已阅读并同意 */
		color: #999999;

		image {
			margin-right: 4px;
			width: 16px;
			height: 16px;
		}
	}

	.itemButton {
		width: 150rpx;
		height: 56rpx;
		background: linear-gradient(90deg, #2366E6 0%, #4373F6 100%);
		border-radius: 40rpx 40rpx 40rpx 40rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 28rpx;
		color: #FFFFFF;
	}

	.bankView {
		padding: 30rpx;
		width: 100%;
		// height: 132rpx;
		background: linear-gradient(90deg, #E77151 1%, #E55654 98%);
		border-radius: 16rpx 16rpx 16rpx 16rpx;
	}

	.bankTitle {
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 24rpx;
		color: #FFFFFF;
	}

	.bankTitle1 {
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 20rpx;
		color: #FFFFFF;
	}

	.bankTitle2 {
		margin-top: 20rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: 400;
		font-size: 30rpx;
		color: #FFFFFF;
	}
</style>